<?php


namespace app\voip\func;


use app\voip\model\QSeats;
use app\voip\model\QSeatsBind;

class SeatsFunc
{
    /**
     * @param $id
     * @return array|false|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static public function getUserSeatsInfo($id)
    {
        $obj=new QSeatsBind();
        return $obj->alias('q1')->
        join('q_seats q2','q1.sid=q2.id')
            ->where('q1.status',1)->where('q1.uid',$id)->field('q2.*')->find();

    }


    /**
     * @param $where
     * @param $rows
     * @param $param
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    static public function getList($where, $rows, $param)
    {
        $obj = new QSeats();
        return $obj->where($where)->order('id desc')->paginate($rows,false,['query'=>$param]);
    }
    /**
     * @param $where
     * @param $rows
     * @param $param
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    static public function getBindList($where, $rows, $param)
    {
        $obj = new QSeatsBind();
        return $obj->alias('s1')->join('admin a1','s1.uid=a1.id')
            ->join('q_seats s2','s1.sid=s2.id')->where($where)
            ->order('s1.id desc')->field('s1.*,s2.number,a1.nickname,a1.username')->paginate($rows,false,['query'=>$param]);
    }
    /**
     * @param $data
     * @return false|int
     */
    static public function add($data)
    {
        $obj = new QSeats($data);
        return $obj->allowField(true)->save();
    }
    /**
     * @param $data
     * @return false|int
     */
    static public function bindAdd($data)
    {
        $obj = new QSeatsBind($data);
        return $obj->allowField(true)->save();
    }

    /**
     * @param $id
     * @return bool
     */
    static public function delBind($id)
    {
        return QSeatsBind::destroy($id);
    }

    /**
     * @param $where
     * @return QSeatsBind
     */
    static public function updateBind($where)
    {
        return QSeatsBind::update($where);
    }
}